<template>
    <view class="importPageWrap">
        <view >
            <view class="flex">
                <view style="margin-right: 40rpx;" class="center flex-column">
                    <view class="stepStyle center">
                        Step1
                    </view>
                    <view class="line"></view>
                </view>
                <view style="height: 320rpx;">
                    <view class="titleStyle" >下载模板</view>
                    <view class="subTitleStyle">点击下载,下载导入模板</view>
                    <view class="btnStyle"@click="downloadTemplate">
                        <image src="./static/downloadBasic.svg" style="width: 44rpx;height: 48rpx;margin-right: 16rpx;" />
                        <text>点击下载</text>
                    </view>
                </view>
            </view>
            <view class="flex">
                <view style="margin-right: 40rpx;" class="center flex-column">
                    <view class="stepStyle center">
                        Step2
                    </view>
                    <view class="line"></view>
                </view>
                <view style="height: 208rpx;">
                    <view class="titleStyle">录入内容</view>
                    <view class="subTitleStyle">按照模板，调整格式，将试题内容录入进去</view>
                </view>
            </view>
            <view class="flex">
                <view style="margin-right: 40rpx;" class="center flex-column">
                    <view class="stepStyle center">
                        Step3
                    </view>
                    <view class="line" style="background-color: transparent;"></view>
                </view>
                <view>
                    <view class="titleStyle">上传试题</view>
                    <view class="subTitleStyle">点击上传按钮，将录入完的试题文档上传上来</view>
                    <view class="btnStyle" @click="uploadFile">
                        <image src="./static/uploadBasic.svg"  style="width: 48rpx;height: 48rpx;margin-right: 16rpx;"/>
                        <text>点击上传</text>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>

import { getBase64ByUrl, notificationFun, onDownLoadFile } from '../utils/PrjUtils';
import { importStructTheoryItem,importStructTheoryWord  } from "./services/myQuestionBankService";
export default {
    data() {
        return {
            filePath: '',
            isExcel: false,
            pInfo:{}
        };
    },
    onLoad({info}) {
        // console.log(option,"---65")
        // console.log(info,"--66")
        // console.log(JSON.parse(decodeURIComponent(info)),"---68")
        let infoData=JSON.parse(decodeURIComponent(info)) ||{}
        this.pInfo=infoData
        this.isExcel=infoData.type=="excel"?true:false
        uni.setNavigationBarTitle({ title: infoData.type == "excel" ? "Excel导入" : "Word导入", })
    },
    methods: {
        // Add your methods here
        downloadTemplate(){
            if(this.isExcel){
                onDownLoadFile("https://qiniu-bjjrzy.bjjrzy.com/bjupi/practice/Excel%E5%AF%BC%E5%85%A5%E9%A2%98%E5%BA%93%E6%A8%A1%E6%9D%BF.xlsx",`${this.pInfo.name}excel模板`)
            }   
            else{
                onDownLoadFile("https://qiniu-bjjrzy.bjjrzy.com/bjupi/practice/%E8%81%8C%E4%B8%9A%E6%8A%80%E8%83%BD%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0%E9%A2%98%E5%BA%93%E8%AF%95%E9%A2%98%E5%AF%BC%E5%85%A5%E6%A8%A1%E7%89%88%E6%A0%BC%E5%BC%8F%E8%AF%B4%E6%98%8E.doc",`${this.pInfo.name}word模板`)
            }
            
        },
        uploadFile() {
            let that=this
            wx.chooseMessageFile({
                type:"file",
                count: 1,  // 可选择的文件数量
                // extension:['doc','docx','xls','xlsx'],  // 可选择的文件类型
                success: function (res) {
                    // console.log(res.tempFiles[0].path)  // 文件路径
                    // 进行文件上传操作
                    that.filePath=res.tempFiles[0].path
                    let urlArr = res.tempFiles[0].name.split('.')
                    let headerText=urlArr[urlArr.length-1]+","
                    getBase64ByUrl(res.tempFiles[0].path,(base64)=>{
                        let param={
                            subjectUuid:that.pInfo.subjectUuid,
                            base64:headerText+base64
                        }
                        if(that.isExcel){
                            importStructTheoryItem(param).then(res=>{
                                notificationFun("上传成功")
                            })
                        }
                        else{
                            importStructTheoryWord(param).then(res=>{
                                notificationFun("上传成功")
                            })
                        }
                    })  
                }
            })
        }
    },

};
</script>

<style scoped lang="scss">
.importPageWrap {
    background-color: #fff;
    height: 100vh;
    box-sizing: border-box;
    padding: 0 34rpx;
    padding-top: 70rpx;
    .line{
        width: 2rpx;
        background-color: #37B874;
        height: calc(100% - 40rpx);
    
    }
    .btnStyle{
        width:  480rpx;
        height: 72rpx;
        border-radius: 24rpx;
        background-color: #37B874;
        color: #fff;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .stepStyle {
        border-radius: 30rpx 30rpx 0 30rpx;
        background-color: #F6FFF7;
        color: #37B874;
        height: 44rpx;
        width: 98rpx;
        font-size: 24rpx;
        font-weight: 600rpx;
    }
    .titleStyle{
        color: #000;
        font-size: 32rpx;
        font-weight: bold;
    }
    .subTitleStyle{
        color: #999;
        font-size: 24rpx;
        margin-top: 12rpx;
        margin-bottom: 30rpx;
    }   
}
</style>